package com.sgb.kjwl.view.ui.adapter.shopping;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.shopping.ShopPriceInfo;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopPriceDetailsAct;

import java.util.List;

public class ShopInfoAdapter extends BaseAdapter {
    ShopPriceDetailsAct shopPriceDetailsAct;
    List<ShopPriceInfo.GoodsListBean> goodsList;
    private ViewHoder viewHoder;
    private int at;

    public ShopInfoAdapter(ShopPriceDetailsAct shopPriceDetailsAct, List<ShopPriceInfo.GoodsListBean> goodsList) {
        this.shopPriceDetailsAct= shopPriceDetailsAct;
        this.goodsList= goodsList;
    }

    @Override
    public int getCount() {
        return goodsList.size();
    }

    @Override
    public Object getItem(int position) {
        return goodsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView ==null){
            convertView = LayoutInflater.from(shopPriceDetailsAct).inflate(R.layout.list_item_shop, null);
            viewHoder = new ViewHoder();
            viewHoder.shopNames = convertView.findViewById(R.id.shop_name);
            viewHoder.shopType=convertView.findViewById(R.id.shop_type);
            viewHoder.shopBrand=convertView.findViewById(R.id.shop_brand);
            viewHoder.shopNum =convertView.findViewById(R.id.shop_num);
            viewHoder.llShopBrands=convertView.findViewById(R.id.ll_shop_brands);
            viewHoder.edShopBrand=convertView.findViewById(R.id.ed_shop_brand);
            viewHoder.edShopMoney=convertView.findViewById(R.id.ed_shop_money);
            convertView.setTag(viewHoder);
        }else {
            viewHoder = (ViewHoder) convertView.getTag();
        }
        if (goodsList.get(position).getType().equals("1")){//商品
            viewHoder.llShopBrands.setVisibility(View.VISIBLE);
        }else {//商砼
            viewHoder.llShopBrands.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(goodsList.get(position).getTcatName())){
            viewHoder.shopNames.setText("");
        }else {
            viewHoder.shopNames.setText(goodsList.get(position).getTcatName()+"");
        }
        if (TextUtils.isEmpty(goodsList.get(position).getAttr())){
            viewHoder.shopType.setText("");
        }else {
            viewHoder.shopType.setText(goodsList.get(position).getAttr()+"");
        }
        if (TextUtils.isEmpty(goodsList.get(position).getGoodsBrand())){
            viewHoder.shopBrand.setText("");
        }else {
            viewHoder.shopBrand.setText(goodsList.get(position).getGoodsBrand()+"");
        }
        viewHoder.shopNum.setText(goodsList.get(position).getNum()+goodsList.get(position).getUnit()+"");
        if (TextUtils.isEmpty(goodsList.get(position).getBrand())){
            viewHoder.edShopBrand.setText("");
        }else {
            viewHoder.edShopBrand.setText(goodsList.get(position).getBrand()+"");
        }
        if (TextUtils.isEmpty(goodsList.get(position).getPrice())){
            viewHoder.edShopMoney.setText("");
        }else {
            viewHoder.edShopMoney.setText(goodsList.get(position).getPrice()+"");
        }
        return convertView;
    }
    class ViewHoder{
        TextView shopNames,shopType,shopBrand,shopNum;
        LinearLayout llShopBrands;
        EditText edShopBrand,edShopMoney;


    }
}
